package com.two.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 添加填充的列名
        this.strictInsertFill(metaObject,"gmtCreate", ()-> LocalDateTime.now(),LocalDateTime.class);
        this.strictInsertFill(metaObject,"gmtModified",  ()-> LocalDateTime.now(),LocalDateTime.class);
        this.strictInsertFill(metaObject, "checktime", () -> LocalDateTime.now(), LocalDateTime.class);
        this.strictInsertFill(metaObject, "requesttime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject,"status",() -> 3,Integer.class);
        this.strictInsertFill(metaObject,"status",() -> 0,Integer.class);
        this.strictInsertFill(metaObject,"tai",() -> 0,Integer.class);
        this.strictInsertFill(metaObject,"tuiTime",  ()-> LocalDateTime.now(),LocalDateTime.class);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 修改填充的列名
        this.strictInsertFill(metaObject,"gmtModified",  ()-> LocalDateTime.now(),LocalDateTime.class);
        this.strictUpdateFill(metaObject, "checktime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "tuiChecktime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
    }
}
